from PyPDF2 import PdfFileReader, PdfFileWriter

def split(pdf_path, new_name):
    pdf = PdfFileReader(pdf_path)
    for page in range(pdf.numPages):
        pdf_writer = PdfFileWriter()
        pdf_writer.addPage(pdf.getPage(page))

        #拼接新的文件名，并写入新的文件
        output = f'{new_name}_{page+1}.pdf'
        with open(output, 'wb') as output_pdf:
            pdf_writer.write(output_pdf)


if __name__ == '__main__':
    path = 'new_dogs.pdf'
    split(path, 'dog')
